package com.leet.tree;

import java.util.ArrayList;
import java.util.List;

public class IncreasingBST {
    List<TreeNode> list = new ArrayList<>();
    public TreeNode increasingBST(TreeNode root) {
        helper(root);
        TreeNode front = new TreeNode(-1);
        TreeNode cur = front;
        for(TreeNode t:list){
            cur.right = new TreeNode(t.val);
            cur.left = null;
            cur = cur.right;
        }
        return front.right;
    }
    void helper(TreeNode ret){
        if (ret == null) return;
        helper(ret.left);
        list.add(ret);
        helper(ret.right);
    }
}
